import Cookies from 'js-cookie'
const TokenKey = 'Admin-Token'

export function getToken() {
  console.log('TokenKey:', TokenKey)
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

const OldTokenKey = 'Old-Token'

export function getOldToken() {
  return Cookies.get(OldTokenKey)
}
export function setOldToken(token) {
  return Cookies.set(OldTokenKey, token)
}
export function removeOldToken() {
  return Cookies.remove(OldTokenKey)
}
// 去登录
export function gotoLogin(redirectUrl) {
  redirectUrl = redirectUrl || window.location.href
  const backUrl = `${location.protocol}//${location.hostname}${location.port ? (':' + location.port) : ''}/auth?redirect_url=${redirectUrl}`
  const url = `${process.env.VUE_APP_LOGIN_URL}?redirect=${backUrl}`
  location.replace(url)
}

export function getOldCompanyId() {
  return localStorage.getItem('OldCompanyId')
}

export function getTenantId() {
  let userInfo = localStorage.getItem('userInfo')
  if (userInfo) {
    userInfo = JSON.parse(userInfo)
    return userInfo.tenantId || ''
  }
  return ''
}

